import wx

from pages import *
from pages.Lesson1Page import Lesson1Page
from pages.Lesson2Page import Lesson2Page
from pages.Lesson3Page import Lesson3Page
from pages.Lesson4Page import Lesson4Page
from pages.Lesson5Page import Lesson5Page


class MainPage(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title="sqli-labs注入测试工具", size=(500, 500))

        grid = wx.GridSizer(5, 4, gap=(0, 0))
        for i in tuple(range(1, 21)):
            btn = wx.Button(self, label='lesson' + str(i))
            btn.Bind(wx.EVT_BUTTON, self.handler_click)
            grid.Add(btn, proportion=1, flag=wx.EXPAND | wx.ALL, border=1)
        self.SetSizer(grid)
        self.setWindowCenter()
        self.Show(True)
        pass

    # 设置窗口居中
    def setWindowCenter(self):
        # 获取屏幕尺寸
        screen_width = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_X)
        screen_height = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)

        # 获取窗口尺寸
        window_width, window_height = self.GetSize()
        # 计算位置
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2
        # 设置位置
        self.SetPosition(wx.Point(x, y))
        pass

    # 按钮事件处理
    def handler_click(self, event):
        btn = event.GetEventObject()
        if str(btn.GetLabel()).endswith("1"):
            Lesson1Page(parent=self, title=btn.GetLabel())
            pass
        if str(btn.GetLabel()).endswith("2"):
            Lesson2Page(parent=self, title=btn.GetLabel())
            pass
        if str(btn.GetLabel()).endswith("3"):
            Lesson3Page(parent=self, title=btn.GetLabel())
            pass
        if str(btn.GetLabel()).endswith("4"):
            Lesson4Page(parent=self, title=btn.GetLabel())
            pass
        if str(btn.GetLabel()).endswith("5"):
            Lesson5Page(parent=self, title=btn.GetLabel())
            pass
        pass
